package com.huluobo.a2109kotlinshopping.category

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import androidx.constraintlayout.widget.ConstraintLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2109kotlinshopping.R

/**
 *  Created by LC on 2024/1/16.
 */
class CategoryParentAdapter(list: MutableList<CategoryBean>) :
    BaseQuickAdapter<CategoryBean, BaseViewHolder>(R.layout.item_category_parent, list) {

    //一级列表第0位的id,初始化时需要使用
    private var selectItemId = 1
    override fun convert(helper: BaseViewHolder, item: CategoryBean) {
        helper.setText(R.id.item_category_parent_tv, item.category_name)

        //如果当前选中的id和item的id相等,就给它一个灰色背景,如果不等就设置为空背景
        helper.getView<ConstraintLayout>(R.id.category_parent_cl).background =
            if (item.id == selectItemId) ColorDrawable(Color.LTGRAY) else null
    }

    fun setSelectItemId(itemId: Int) {
        selectItemId = itemId
        notifyDataSetChanged()
    }
}